package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.CustomDao;
import ysq.xyg.model.Custom;
import ysq.xyg.service.CustomService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("customService")
public class CustomServiceImpl extends BaseServiceImpl<Custom> implements CustomService {
    @Resource
    private CustomDao customDao;

    @Autowired
    public void setBaseDao(CustomDao customDao) {
        this.baseDao = customDao;
    }

    @Override
    public PageInfo<Custom> pageInfo(Custom custom, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy(" kind asc,sort desc");
        //通用Example查询
        Example example = new Example(Custom.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(custom.getName())) {
            criteria.andLike("name","%"+custom.getName()+"%");
        }
        if (StringUtil.isNotEmpty(custom.getKind())) {
            criteria.andEqualTo("kind",custom.getKind());
        }
        List<Custom> list=customDao.selectByExample(example);
        return new PageInfo<Custom>(list);
    }
    @Override
    public List<Custom> list(Custom custom) {
        //通用Example查询
        Example example = new Example(Custom.class);
        example.setOrderByClause(" kind asc,sort desc");
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(custom.getName())) {
            criteria.andLike("name","%"+custom.getName()+"%");
        }
        if (StringUtil.isNotEmpty(custom.getKind())) {
            criteria.andEqualTo("kind",custom.getKind());
        }
        if (StringUtil.isNotEmpty(custom.getNotKind())) {
            criteria.andNotEqualTo("kind",custom.getKind());
        }
        List<Custom> list=customDao.selectByExample(example);
        return list;
    }
}
